<?php

/**
 * Интернет сайт
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class Type4Form extends BaseMaterialForm
{
  public function configure()
  {
  	
  		unset( 
  		$this['created_at'],  
  		$this['updated_at'],  
  		$this['user_id'], 
  		$this['see'], 
  		$this['click'], 
  		$this['country'],
  		$this['link'],
  		$this['custom_int1'],
  		$this['custom_int2'],
  		$this['custom_int3'],
  		$this['custom_text1'],
  		$this['custom_text2'],
  		$this['custom_text3'],
  		$this['custom_char1'],
  		$this['custom_char2'],
  		$this['custom_char3'],
  		$this['stat'],
  		$this['city']);
  		
  		$c = new Criteria();
  		$c->add(FolderPeer::USER_ID,sfContext::getInstance()->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' )); 
  		$c->addAnd(FolderPeer::TREE_PARENT,1,Criteria::NOT_EQUAL); 
  		
  		$this->setWidgets(array(
      'id'               => new sfWidgetFormInputHidden(),
      'title' =>  new sfWidgetFormInput(array(),array('size'=>50)),
  	  'type_id'           => new sfWidgetFormInputHidden(array(), array('value' =>'4', 'class'=>'test')),	
  	  'photo_path' =>  new inputImageTag (  array (), array('mat_id'=>$this->object->getId(),'folder'=>'site') ), 
  	  'short_content' => new sfWidgetFormTextareaNickEdit(array(),array('class'   =>  'material_short_content','style'=>'width:620px')),
  	  'content' => new sfWidgetFormTextareaNickEdit(array(),array('class'   =>  'material_content','style'=>'width:620px')),
  	  'seo_title' =>  new sfWidgetFormTextarea(array(),array('style'=>'width:600px; height: 40px')),				
  	  'seo_keyword' =>  new sfWidgetFormTextarea(array(),array('style'=>'width:600px; height: 40px')),	
  	  'mat2_folder_list' => new sfWidgetFormPropelChoiceMany(array('model' => 'Folder','multiple' => true, 'expanded' => true, 'criteria'=>$c))
    ));
  		
  		
  		$this->widgetSchema->setLabels(array(  
		'title'    => 'Заголовок',  
		'photo_path'   => 'Рисунок',  
  		'content'   => 'Содержимое',
  		'seo_title'   => 'SEO заголовок',
  		'seo_keyword'   => 'SEO слова для поиска',
  		'mat2_folder_list'   => 'Каталоги',
		'short_content' => 'Короткое описание',));
  		
    
     $this->validatorSchema['photo_path'] = new sfValidatorFile(array(
        'required'   => false,
        'path'       => sfConfig::get('sf_web_dir').'/uploads/material/site',
        'mime_types' => 'web_images',
        'max_size'   => 380000, // 360 kB
        'validated_file_class' => 'sfMatFileValidatedFile'
        ));
  		 $this->widgetSchema->setNameFormat('material[%s]');
  
  }
  
   public function saveMat2FolderList($con = null)
  {
  	 parent::saveMat2FolderList();
  	 $c = new Criteria();
  	 $c->add(FolderPeer::TREE_PARENT,1);
  	 $c->addAnd(FolderPeer::USER_ID,sfContext::getInstance()->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
  	 $rf = FolderPeer::doSelectOne($c);
  	 $rel = new Mat2Folder();
  	 $rel->setFolderId($rf->getId());
  	 $rel->setMaterialId($this->object->getPrimaryKey());
  	 $rel->save();
  	
  	
  }
}
